//
// Created by root on 24-7-15.
//
#include "../include/io.h"
#include "../include/makecodedfine.h"
#include "../include/vga.h"

void print_char(int p, int c);

extern int current_print_position;

void init_position();

void printk(char *prompt, ...);

static int curosr_position = 0;
static int __volatile__ special_key = 0;

void write_console(char k) {
    print_char(current_print_position, k);
    current_print_position++;
    current_print_position++;
    if (curosr_position != 80) {
        curosr_position++;
        movcursor(24, curosr_position);
    } else {
        init_position();
        rollup();
        curosr_position = 0;
        movcursor(24, 0);
    }
}

void keyboarddrive(unsigned char m) {
    switch ( (int)m) {
        case SCAN_CODE_A:
            write_console('a');
            break;
        case SCAN_CODE_B: write_console('b');
            break;
        case SCAN_CODE_C: write_console('c');
            break;
        case SCAN_CODE_D: write_console('d');
            break;
        case SCAN_CODE_E: write_console('e');
            break;
        case SCAN_CODE_F: write_console('f');
            break;;
        case SCAN_CODE_G: write_console('g');
            break;;
        case SCAN_CODE_H: write_console('h');
            break;;
        case SCAN_CODE_I: write_console('i');
            break;;
        case SCAN_CODE_J: write_console('j');
            break;;
        case SCAN_CODE_K: write_console('k');
            break;;
        case SCAN_CODE_L: write_console('l');
            break;;
        case SCAN_CODE_M: write_console('m');
            break;;
        case SCAN_CODE_N: write_console('n');
            break;
        case SCAN_CODE_O: write_console('o');
            break;
        case SCAN_CODE_P: write_console('p');
            break;;
        case SCAN_CODE_Q: write_console('q');
            break;;
        case SCAN_CODE_R: write_console('r');
            break;;
        case SCAN_CODE_S: write_console('s');
            break;;
        case SCAN_CODE_T: write_console('t');
            break;;
        case SCAN_CODE_U: write_console('u');
            break;
        case SCAN_CODE_V: write_console('v');
            break;
        case SCAN_CODE_W: write_console('w');
            break;
        case SCAN_CODE_X: write_console('x');
            break;
        case SCAN_CODE_Y: write_console('y');
            break;
        case SCAN_CODE_Z: write_console('z');
            break;
        case SCAN_CODE_left_shift:
            special_key = SCAN_CODE_left_shift;
            break;
        case 0xAA:
            special_key = 0;
            break;
        case SCAN_CODE_2: if (special_key == SCAN_CODE_left_shift) {
                write_console('@');

            } else {
                write_console('2');
            }
            break;
        default: break;
    }
}
